package org.zsl.service;

import org.apache.ibatis.annotations.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zsl.mapper.ProductMapper;
import org.zsl.model.Product;
import org.zsl.model.ResponseMessage;

import java.util.List;

@Service
public class ProductService {

     @Autowired
     private ProductMapper mapper;


     public List<Product> getAll(){

           return  mapper.selectAll();
     }

     public ResponseMessage getProductsByExample(Product product){

          ResponseMessage message = new ResponseMessage();

           message.setData(mapper.selectByExample(product));
           message.setSuccess(true);

           return  message;

     }

     /**
      * 库存修改
      * */
     public ResponseMessage inStock(Integer productId,Integer quantity){
         ResponseMessage message = new ResponseMessage();

         Product product = mapper.selectById(productId);

         product.setQuantity(product.getQuantity() + quantity);

         Boolean success=  mapper.update(product)>0?true:false;
         message.setSuccess(success);

         return  message;
     }
}
